package com.aaa.service.Impl;

import com.aaa.mapper.EmpMapper;
import com.aaa.mapper.StrudnetMapper;
import com.aaa.pojos.*;
import com.aaa.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Resource
    private EmpMapper empMapper;
    @Resource
    private StrudnetMapper strudnetMapper;
    @Override
    public EmpJobReportData empJobData() {
        //执行SQL语句，根据job职位分组统计人数，封装成EmpJob集合
        List<EmpJob> list = empMapper.selectJobCnt();
        log.info("list"+list);

        //获取职位名称列表
        List<String> jobList = list.stream().map(EmpJob::getJob).collect(Collectors.toList());
        //获取职位人数列表
        List<Integer> dataList = list.stream().map(EmpJob::getCt).collect(Collectors.toList());
//        List<String> jobList =list.stream().map(new Function<EmpJob, String>() {
//            @Override
//            public String apply(EmpJob empJob) {
//                return  empJob.getJob();
//            }
//        }).collect(Collectors.toList());
        EmpJobReportData empJobReportData =new EmpJobReportData(jobList, dataList);
        //封装成客户端要求的响应结果
        log.info("empJobReportData响应结果{}"+empJobReportData);
        return empJobReportData;
    }

    @Override
    public List<EmpGender> empGender() {
        List<EmpGender> list = empMapper.empGender();
        return list;
    }

    @Override
    public List<StudentGender> degree() {
        List<StudentGender> list=strudnetMapper.degree();
        return list;
    }

    @Override
    public StudentJobReportData countData() {
        List<StudentJob> list=strudnetMapper.countData();
        log.info("list结果"+list);
        List<String> clazzList = list.stream().map(StudentJob::getJob).collect(Collectors.toList());
        List<Integer> dataList = list.stream().map(new Function<StudentJob, Integer>() {
            @Override
            public Integer apply(StudentJob studentJob) {
                return studentJob.getCnt();
            }
        }).collect(Collectors.toList());
        StudentJobReportData studentJobReportData=new StudentJobReportData(clazzList,dataList);
        return studentJobReportData;
    }
}
